//
//  MessageProjectEditViewController.m
//  MagictoLane
//
//  Created by 锋 on 2018/1/5.
//  Copyright © 2018年 HUAYU. All rights reserved.
//

#import "MessageProjectEditViewController.h"
#import "ProducePointTableViewCell.h"
#import "ProdoceJobDescriptionTableViewCell.h"
#import "AddMachineViewController.h"
#import "AddPointViewController.h"
#import "ProducePointModel.h"
#import "SelectWorkKindModel.h"
#import "AddMachineModel.h"
#import "ProduceLineKindViewController.h"
#import "MyProductionLineViewController.h"
#import "ProduceLineDetailViewController.h"
#import "ProduceMachinesModel.h"
#import "ProduceSpotsModel.h"
#import "AddWorkerViewController.h"
#import "SpecialWorkerViewController.h"
#import "DataPicturesViewController.h"
#import "PGDatePicker.h"
#import "PGDatePickManager.h"

@interface MessageProjectEditViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, PGDatePickerDelegate>
{
    NSArray *productionNameArr;
    NSMutableArray *rightProduceNameArr;
    NSInteger whichPicker;
    NSDateComponents *startComponent;
    NSDateComponents *endComponent;
    NSString *startTimeStr;
    NSString *endTimeStr;
    
    UILabel *dayLabel;
    UILabel *nameLabel;
    UIButton *addProducePointBtn;
    UILabel *jobNameLabel;
    UILabel *workerNameLabel;
    UIButton *workerAddProducePointBtn;
    UIButton *jobAddProducePointBtn;
    
    CGFloat scrollViewOffSetY;
    CGFloat remainingDistanceY;
    CGFloat beforeMigrationY;
    NSArray *nameArr;
    UITextField *textField4;
    UITextField *textField5;
    NSString *str4;
    NSString *str5;
    NSString *str6;
    NSString *priceStr;
    NSString *managerPrice;
}
@property (nonatomic, strong) UITableView *addProductionLineTableView;
@property (nonatomic, strong) SelectWorkKindModel *selectWorkKindModel;
@property (nonatomic, strong) AddMachineModel *addMachineModel;
@property (nonatomic, strong) ProduceLineKindModel *produceLineKindModel;

@end

@implementation MessageProjectEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    productionNameArr = @[@"项目金额", @"项目时间"];
    ProjectDetailModel *detailModel = _projectDetailArr[0];
    str4 = detailModel.expressFee;
    str5 = detailModel.packingFee;
    str6 = detailModel.bomNum;
    startTimeStr = detailModel.startDate;
    endTimeStr = detailModel.endDate;
    //    if ([detailModel.area isKindOfClass:[NSNull class]] || [detailModel.area isEqualToString:@""]) {
    nameArr = @[@"Bom资料", @"物料编号", @"收货地址", @"物流费用", @"包装费用"];
    //    } else {
    //        nameArr = @[@"Bom资料", @"发布区域", @"收货地址", @"物流费用", @"包装费用"];
    //    }
    
    //    self.produceMachineNameArr = @[].mutableCopy;
    //    _produceMachineModelArr = @[].mutableCopy;
    //    self.producePointNameArr = @[].mutableCopy;
    //    rightProduceNameArr = @[@"", @""].mutableCopy;
    //    _machineNumberArr = @[].mutableCopy;
    //    for (int i = 0; i < _detailModel.machines.count; i++) {
    //        ProduceMachinesModel *machinesModel = _detailModel.machines[i];
    //        [self.produceMachineNameArr addObject:machinesModel.machine.name];
    //        AddMachineModel *tempModel = [[AddMachineModel alloc] init];
    //        tempModel.ID = machinesModel.machine.ID;
    //        tempModel.name = machinesModel.machine.name;
    //        [_produceMachineModelArr addObject:tempModel];
    //        [_machineNumberArr addObject:machinesModel.count];
    //    }
    //    for (int i = 0; i < _detailModel.spots.count; i++) {
    //        ProduceSpotsModel *spotsModel = _detailModel.spots[i];
    //        ProducePointModel *model = [[ProducePointModel alloc] init];
    //        model.nameStr = spotsModel.name;
    //        model.jobDetailStr = spotsModel.remark;
    //        [self.producePointNameArr addObject:model];
    //    }
    //    _produceLineKindModel = _detailModel.category;
    //    rightProduceNameArr[0] = _detailModel.name;
    //    rightProduceNameArr[1] = _detailModel.rent;
    
    [self setupUI];
    [self setupMyProductionLineTableView];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jianpantanchu:) name:UIKeyboardDidShowNotification object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jianpanhuishou:) name:UIKeyboardDidHideNotification object:nil];
    if (_specialWorkerModel && ![_specialWorkerModel isKindOfClass:[NSNull class]]) {
        [_produceWorkerNameArr addObject:_specialWorkerModel.name];
        [_workNumberArr addObject:@"1"];
        WorkModel *workModel = [[WorkModel alloc] init];
        workModel.workId = _specialWorkerModel.ID;
        workModel.count = _workNumberArr.lastObject;
        [_produceWorkerModelArr addObject:workModel];
        [_addProductionLineTableView reloadData];
    }
    _specialWorkerModel = nil;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

- (void)setupUI {
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveProductionLine)];
    rightBtn.tintColor = [UIColor whiteColor];
    [rightBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], UITextAttributeFont,nil] forState:UIControlStateNormal];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.rightBarButtonItem = rightBtn;
    self.navigationItem.title = @"项目详情";
    self.view.backgroundColor = RGB(242, 242, 242);
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    singleTap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:singleTap];
}

- (void)setupMyProductionLineTableView {
    _addProductionLineTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - STA_NAV_HEIGHT - SCREER_HeiX) style:UITableViewStyleGrouped];
    _addProductionLineTableView.delegate = self;
    _addProductionLineTableView.dataSource = self;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.000001)];
    view.backgroundColor = [UIColor whiteColor];
    _addProductionLineTableView.tableHeaderView = view;
    _addProductionLineTableView.tableFooterView = view;
    _addProductionLineTableView.backgroundColor = [UIColor whiteColor];
    _addProductionLineTableView.backgroundColor = RGB(242, 242, 242);
    if (@available(iOS 11.0, *)) {
        _addProductionLineTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    _addProductionLineTableView.estimatedRowHeight = 0;
    _addProductionLineTableView.estimatedSectionHeaderHeight = 0;
    _addProductionLineTableView.estimatedSectionFooterHeight = 0;
    //    _addProductionLineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_addProductionLineTableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 6;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return productionNameArr.count + 2;
    } else if (section == 1) {
        return _produceMachineNameArr.count + 1;
    } else if (section == 2) {
        return _produceWorkerNameArr.count + 1;
    } else if (section == 3) {
        return _producePointNameArr.count + 1;
    } else if (section == 4) {
        return nameArr.count;
    } else if (section == 5) {
        return 2;
    } else {
        return 0;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else {
        return 5;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.000001;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ProjectDetailModel *detailModel = _projectDetailArr[0];
    if (indexPath.section == 0) {
        NSString *ID = @"cell1";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
        }
        if (indexPath.row == 2 || indexPath.row == 3) {
            cell.textLabel.text = productionNameArr[indexPath.row - 2];
        } else if (indexPath.row == 0) {
            cell.textLabel.text = detailModel.name;
        } else if (indexPath.row == 1) {
            cell.textLabel.text = detailModel.productCategoryName;
        }
        
        if (![self.view viewWithTag:indexPath.row + 100]) {
            if (indexPath.row == 2) {
                CGFloat width = SCREEN_WIDTH - 150;
                UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - width - 50, 0, width, 44)];
                textField.backgroundColor = [UIColor clearColor];
                textField.delegate = self;
                textField.tag = 102;
                textField.font = [UIFont systemFontOfSize:15];
                textField.textAlignment = NSTextAlignmentLeft;
                textField.textColor = UIColorHexValue(0xB3B3B3);
                if (!dayLabel) {
                    dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 50, 0, 50, 44)];
                    dayLabel.text = @"(元)";
                    dayLabel.textColor = UIColorHexValue(0xB3B3B3);
                    dayLabel.backgroundColor = [UIColor whiteColor];
                    dayLabel.font = [UIFont systemFontOfSize:15];
                    dayLabel.textAlignment = NSTextAlignmentLeft;
                    [cell.contentView addSubview:dayLabel];
                }
                textField.placeholder = @"请输入项目总金额";
                textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
                [cell.contentView addSubview:textField];
            } else if (indexPath.row == 3) {
                CGFloat width = (SCREEN_WIDTH-100-30)/2;
                UITextField *startTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, width, 44)];
                UILabel *wordLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(startTextField.frame) + 5, 0, 20, 44)];
                UITextField *endTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(wordLabel.frame) + 5, 0, width, 44)];
                startTextField.delegate = self;
                startTextField.tag = 103;
                startTextField.font = [UIFont systemFontOfSize:15];
                startTextField.textAlignment = NSTextAlignmentCenter;
                startTextField.textColor = UIColorHexValue(0xB3B3B3);
                startTextField.placeholder = @"请输入开始时间";
                startTextField.enabled = NO;
                
                endTextField.delegate = self;
                endTextField.tag = 104;
                endTextField.font = [UIFont systemFontOfSize:15];
                endTextField.textAlignment = NSTextAlignmentCenter;
                endTextField.textColor = UIColorHexValue(0xB3B3B3);
                endTextField.placeholder = @"请输入结束时间";
                endTextField.enabled = NO;
                wordLabel.text = @"到";
                wordLabel.textColor = UIColorHexValue(0x4D4D4D);
                wordLabel.backgroundColor = [UIColor whiteColor];
                wordLabel.font = [UIFont systemFontOfSize:15];
                wordLabel.textAlignment = NSTextAlignmentCenter;
                [cell.contentView addSubview:wordLabel];
                
                UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 43, SCREEN_WIDTH - 15, 1)];
                lineLabel.backgroundColor = RGB(238, 239, 238);
                [cell.contentView addSubview:lineLabel];
                [cell.contentView addSubview:startTextField];
                [cell.contentView addSubview:endTextField];
                UIButton *startBtn = [ZCControl createButtonWithFrame:CGRectMake(100, 0, width, 44) ImageName:nil Target:self Action:@selector(onClickStartBtn) Title:nil Font:10];
                startBtn.backgroundColor = [UIColor clearColor];
                [cell.contentView addSubview:startBtn];
                UIButton *endBtn = [ZCControl createButtonWithFrame:CGRectMake(CGRectGetMaxX(wordLabel.frame) + 5, 0, width, 44) ImageName:nil Target:self Action:@selector(onClickEndBtn) Title:nil Font:10];
                endBtn.backgroundColor = [UIColor clearColor];
                [cell.contentView addSubview:endBtn];
            }
            
        }
        if (indexPath.row == 1) {
            //            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 43, SCREEN_WIDTH - 15, 1)];
            lineLabel.backgroundColor = RGB(238, 239, 238);
            [cell.contentView addSubview:lineLabel];
        }
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.textColor = UIColorHexValue(0x4D4D4D);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        UITextField *textField = [cell.contentView viewWithTag:102];
        UITextField *textField2 = [cell.contentView viewWithTag:103];
        UITextField *textField3 = [cell.contentView viewWithTag:104];
        textField.text = detailModel.budget;
        textField2.text = startTimeStr;
        textField3.text = endTimeStr;
        
        return cell;
    } else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            NSString *ID = @"cell2";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            }
            if (!nameLabel) {
                nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 100, 44)];
                nameLabel.text = @"生产设备";
                nameLabel.textColor = UIColorHexValue(0x4D4D4D);
                nameLabel.backgroundColor = [UIColor whiteColor];
                nameLabel.font = [UIFont systemFontOfSize:16];
                nameLabel.textAlignment = NSTextAlignmentLeft;
                [cell.contentView addSubview:nameLabel];
            }
            if (!addProducePointBtn) {
                addProducePointBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 50, 0, 50, 44)];
                addProducePointBtn.backgroundColor = [UIColor whiteColor];
                [addProducePointBtn setImage:[UIImage imageNamed:@"jiahao"] forState:UIControlStateNormal];
                [addProducePointBtn addTarget:self action:@selector(onClickAddProduceMachineBtn:) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:addProducePointBtn];
                UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 43, SCREEN_WIDTH, 1)];
                lineLabel.backgroundColor = RGB(238, 239, 238);
                [cell.contentView addSubview:lineLabel];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        } else {
            ProducePointTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"ProducePointTableViewCell" owner:self options:nil].lastObject;
            
            cell.producePointNameLabel.text = _produceMachineNameArr[indexPath.row - 1];
            cell.numberTextField.textColor = UIColorHexValue(0xB3B3B3);
            cell.numberTextField.layer.borderColor = UIColorHexValue(0xB3B3B3).CGColor;
            cell.numberTextField.layer.borderWidth = 1;
            cell.numberTextField.delegate = self;
            cell.numberTextField.tag = 1000 + indexPath.row;
            cell.numberTextField.text = _machineNumberArr[indexPath.row - 1];
            cell.numberTextField.keyboardType = UIKeyboardTypePhonePad;
            cell.minusBtn.layer.borderColor = UIColorHexValue(0xB3B3B3).CGColor;
            cell.minusBtn.layer.borderWidth = 1;
            cell.minusBtn.tag = indexPath.row + 500;
            [cell.minusBtn addTarget:self action:@selector(onClickMinusNumberBtn:) forControlEvents:UIControlEventTouchUpInside];
            cell.addBtn.layer.borderColor = UIColorHexValue(0xB3B3B3).CGColor;
            cell.addBtn.layer.borderWidth = 1;
            cell.addBtn.tag = indexPath.row + 500;
            [cell.addBtn addTarget:self action:@selector(onClickAddNumberBtn:) forControlEvents:UIControlEventTouchUpInside];
            cell.deleteBtn.tag = indexPath.row;
            [cell.deleteBtn addTarget:self action:@selector(deleteProduceMachine:) forControlEvents:UIControlEventTouchUpInside];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (indexPath.row == _produceMachineNameArr.count) {
                cell.lineLabel.hidden = YES;
            }
            
            return cell;
        }
        
    } else if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            NSString *ID = @"cell3";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            }
            if (!workerNameLabel) {
                workerNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 100, 44)];
                workerNameLabel.text = @"所需工人";
                workerNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                workerNameLabel.backgroundColor = [UIColor whiteColor];
                workerNameLabel.font = [UIFont systemFontOfSize:16];
                workerNameLabel.textAlignment = NSTextAlignmentLeft;
                [cell.contentView addSubview:workerNameLabel];
            }
            if (!workerAddProducePointBtn) {
                workerAddProducePointBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 100-12, 0, 100, 44)];
                workerAddProducePointBtn.backgroundColor = [UIColor whiteColor];
                workerAddProducePointBtn.enabled = NO;
                [workerAddProducePointBtn addTarget:self action:@selector(onClickAddProduceWorkerBtn:) forControlEvents:UIControlEventTouchUpInside];
                workerAddProducePointBtn.titleLabel.font = [UIFont systemFontOfSize:16];
                [workerAddProducePointBtn setTitleColor:UIColorHexValue(0x4D4D4D) forState:UIControlStateNormal];
                workerAddProducePointBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
                [cell.contentView addSubview:workerAddProducePointBtn];
                UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 43, SCREEN_WIDTH, 1)];
                lineLabel.backgroundColor = RGB(238, 239, 238);
                [cell.contentView addSubview:lineLabel];
            }
            NSInteger num = 0;
            for (int i = 0; i < _workNumberArr.count; i++) {
                NSInteger workNum = [_workNumberArr[i] integerValue];
                num = num + workNum;
            }
            [workerAddProducePointBtn setTitle:[NSString stringWithFormat:@"%ld人", num] forState:UIControlStateNormal];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        } else {
            ProducePointTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"ProducePointTableViewCell" owner:self options:nil].lastObject;
            cell.minusBtn.hidden = YES;
            cell.addBtn.hidden = YES;
            cell.deleteBtn.hidden = YES;
            cell.numberTextField.enabled = NO;
            cell.numberTextField.borderStyle = UITextBorderStyleNone;
            cell.numberTextField.textAlignment = NSTextAlignmentRight;
            cell.numberTextField.frame = CGRectMake(SCREEN_WIDTH - cell.numberTextField.frame.size.width - 12, cell.numberTextField.frame.origin.y, cell.numberTextField.frame.size.width, cell.numberTextField.frame.size.height);
            if (indexPath.row == 1) {
                cell.producePointNameLabel.text = @"管理者";
                cell.numberTextField.text = @"x1";
            } else {
                if (_produceWorkerNameArr.count>1) {
                    cell.producePointNameLabel.text = _produceWorkerNameArr[indexPath.row - 1];
                    cell.numberTextField.text = [NSString stringWithFormat:@"x%@", _workNumberArr[indexPath.row - 1]];
                }
            }
            
            cell.numberTextField.textColor = UIColorHexValue(0x4D4D4D);
//            cell.numberTextField.layer.borderColor = UIColorHexValue(0xB3B3B3).CGColor;
//            cell.numberTextField.layer.borderWidth = 1;
            cell.numberTextField.delegate = self;
            cell.numberTextField.tag = 2000 + indexPath.row;
            cell.numberTextField.keyboardType = UIKeyboardTypePhonePad;
            cell.minusBtn.layer.borderColor = UIColorHexValue(0xB3B3B3).CGColor;
            cell.minusBtn.layer.borderWidth = 1;
            cell.minusBtn.tag = indexPath.row + 500;
            [cell.minusBtn addTarget:self action:@selector(onClickMinusWorkerNumberBtn:) forControlEvents:UIControlEventTouchUpInside];
            cell.addBtn.layer.borderColor = UIColorHexValue(0xB3B3B3).CGColor;
            cell.addBtn.layer.borderWidth = 1;
            cell.addBtn.tag = indexPath.row + 500;
            [cell.addBtn addTarget:self action:@selector(onClickAddWorkerNumberBtn:) forControlEvents:UIControlEventTouchUpInside];
            cell.deleteBtn.tag = indexPath.row;
            [cell.deleteBtn addTarget:self action:@selector(deleteProduceWorker:) forControlEvents:UIControlEventTouchUpInside];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (indexPath.row == _produceMachineNameArr.count) {
                cell.lineLabel.hidden = YES;
            }
            
            return cell;
        }
    } else if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            NSString *ID = @"cell4";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
            }
            if (!jobNameLabel) {
                jobNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 100, 44)];
                jobNameLabel.text = @"生产节点";
                jobNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                jobNameLabel.backgroundColor = [UIColor whiteColor];
                jobNameLabel.font = [UIFont systemFontOfSize:16];
                jobNameLabel.textAlignment = NSTextAlignmentLeft;
                [cell.contentView addSubview:jobNameLabel];
            }
            if (!jobAddProducePointBtn) {
                jobAddProducePointBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 50, 0, 50, 44)];
                jobAddProducePointBtn.backgroundColor = [UIColor whiteColor];
                [jobAddProducePointBtn setImage:[UIImage imageNamed:@"jiahao"] forState:UIControlStateNormal];
                [jobAddProducePointBtn addTarget:self action:@selector(onClickAddProducePointBtn:) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:jobAddProducePointBtn];
                UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 43, SCREEN_WIDTH, 1)];
                lineLabel.backgroundColor = RGB(238, 239, 238);
                [cell.contentView addSubview:lineLabel];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        } else {
            ProdoceJobDescriptionTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"ProdoceJobDescriptionTableViewCell" owner:self options:nil].lastObject;
            cell.jobDescriptionTextField.delegate = self;
            if (indexPath.row == 1) {
                [cell.signBtn setImage:[UIImage imageNamed:@"guanlizhe"] forState:UIControlStateNormal];
                cell.jobDescriptionTextField.hidden = YES;
                cell.deleteBtn.hidden = YES;
                cell.nameLabel.text = @"管理者";
                cell.priceLabel.frame = CGRectMake(cell.priceLabel.frame.origin.x, cell.priceLabel.frame.origin.y, cell.contentView.frame.size.width-cell.priceLabel.frame.origin.x-30, cell.priceLabel.frame.size.height);
                if (managerPrice.length>0) {
                    cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", managerPrice];
                } else {
                    ProducePointModel *model = _producePointNameArr[indexPath.row - 1];
                    if (model.priceStr&&![model.priceStr isEqual:@""]&&![model.priceStr isKindOfClass:[NSNull class]]) {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.priceStr];
                    } else {
                        cell.priceLabel.textAlignment = NSTextAlignmentRight;
                        cell.priceLabel.text = @"设置管理者工价";
                    }
                }
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            } else {
                if (_producePointNameArr.count > 1) {
                    ProducePointModel *model = _producePointNameArr[indexPath.row - 1];
                    cell.nameLabel.text = model.nameStr;
                    cell.jobDescriptionTextField.text = model.jobDetailStr;
                    cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.priceStr];
                }
                cell.jobDescriptionTextField.textColor = UIColorHexValue(0xB3B3B3);
                cell.jobDescriptionTextField.delegate = self;
                cell.deleteBtn.tag = indexPath.row;
                [cell.deleteBtn addTarget:self action:@selector(deleteProducePoint:) forControlEvents:UIControlEventTouchUpInside];
                [cell.signBtn setTitle:[NSString stringWithFormat:@"%ld", indexPath.row - 1] forState:UIControlStateNormal];
                
            }
            if (indexPath.row == _producePointNameArr.count + 1) {
                cell.lineLabel.hidden = YES;
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
    } else if (indexPath.section == 4) {
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        if (indexPath.row == 0) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        } else {
            if (nameArr.count == 5) {
                if (indexPath.row != 2 && indexPath.row != 3) {
                    if (![cell.contentView viewWithTag:600 + indexPath.row]) {
                        UILabel *detailNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                        detailNameLabel.numberOfLines = 0;
                        detailNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                        detailNameLabel.tag = 600 + indexPath.row;
                        detailNameLabel.font = [UIFont systemFontOfSize:14];
                        [cell.contentView addSubview:detailNameLabel];
                    }
                } else {
                    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                    textField.backgroundColor = [UIColor clearColor];
                    textField.delegate = self;
                    textField.tag = indexPath.row + 600;
                    textField.textAlignment = NSTextAlignmentLeft;
                    textField.textColor = UIColorHexValue(0x4D4D4D);
                    if (indexPath.row == 2) {
                        textField.placeholder = @"请输入快递费用";
                    } else if (indexPath.row == 3) {
                        textField.placeholder = @"请输入包装费用";
                    }
                    textField.font = [UIFont systemFontOfSize:14];
                    textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
                    [cell.contentView addSubview:textField];
                }
            } else if (nameArr.count == 6) {
                if (indexPath.row != 4 && indexPath.row != 5 && indexPath.row != 1) {
                    if (![cell.contentView viewWithTag:600 + indexPath.row]) {
                        UILabel *detailNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                        detailNameLabel.numberOfLines = 0;
                        detailNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                        detailNameLabel.tag = 600 + indexPath.row;
                        detailNameLabel.font = [UIFont systemFontOfSize:14];
                        [cell.contentView addSubview:detailNameLabel];
                    }
                } else {
                    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                    textField.backgroundColor = [UIColor clearColor];
                    textField.delegate = self;
                    textField.tag = indexPath.row + 600;
                    textField.textAlignment = NSTextAlignmentLeft;
                    textField.textColor = UIColorHexValue(0x4D4D4D);
                    textField.font = [UIFont systemFontOfSize:14];
                    if (indexPath.row == 4) {
                        textField.placeholder = @"请输入快递费用";
                    } else if (indexPath.row == 5) {
                        textField.placeholder = @"请输入包装费用";
                    } else if (indexPath.row == 1) {
                        textField.placeholder = @"请输入包装费用";
                    }
                    textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
                    [cell.contentView addSubview:textField];
                }
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        UILabel *detailNameLabel = [cell.contentView viewWithTag:600 + indexPath.row];
        //        if ([detailModel.area isKindOfClass:[NSNull class]] || [detailModel.area isEqualToString:@""]) {
        if (indexPath.row == 2) {
            detailNameLabel.text = detailModel.deliveryAddress;
        } else if (indexPath.row == 3) {
            UITextField *textField = [cell.contentView viewWithTag:indexPath.row + 600];
            textField.text = [NSString stringWithFormat:@"￥%@", detailModel.expressFee];
        } else if (indexPath.row == 4) {
            UITextField *textField = [cell.contentView viewWithTag:indexPath.row + 600];
            textField.text = [NSString stringWithFormat:@"￥%@", detailModel.packingFee];
        } else if (indexPath.row == 5) {
            detailNameLabel.text = detailModel.packRemark;
        } else if (indexPath.row == 1) {
            UITextField *textField = [cell.contentView viewWithTag:indexPath.row + 600];
            textField.text = detailModel.bomNum;
        }
        //        } else {
        //            if (indexPath.row == 1) {
        //                detailNameLabel.text = [NSString stringWithFormat:@"%@%@%@", detailModel.areaProvinceName, detailModel.areaCityName, detailModel.areaName];
        //            } else if (indexPath.row == 2) {
        //                detailNameLabel.text = detailModel.deliveryAddress;
        //            } else if (indexPath.row == 3) {
        //                UITextField *textField = [cell.contentView viewWithTag:indexPath.row + 600];
        //                textField.text = [NSString stringWithFormat:@"￥%@", detailModel.expressFee];
        //            } else if (indexPath.row == 4) {
        //                UITextField *textField = [cell.contentView viewWithTag:indexPath.row + 600];
        //                textField.text = [NSString stringWithFormat:@"￥%@", detailModel.packingFee];
        //            } else if (indexPath.row == 5) {
        //                detailNameLabel.text = detailModel.packRemark;
        //            }
        //        }
        
        cell.textLabel.textColor = UIColorHexValue(0x4D4D4D);
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.text = nameArr[indexPath.row];
        
        return cell;
    } else if (indexPath.section == 5) {
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        if (indexPath.row == 0) {
            cell.textLabel.text = @"包装详情";
            cell.textLabel.textColor = UIColorHexValue(0x4D4D4D);
            if ([detailModel.packType isEqual:@"1"]) {
                cell.detailTextLabel.text = @"简易包装";
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            } else if ([detailModel.packType isEqual:@"2"]) {
                if ([detailModel.wrapperType isEqual:@"1"]) {
                    cell.detailTextLabel.text = @"专业包装(自带材料)";
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                } else if ([detailModel.wrapperType isEqual:@"2"]) {
                    cell.detailTextLabel.text = @"专业包装(指定材料)";
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                }
            }
            
            cell.detailTextLabel.textColor = UIColorHexValue(0x4D4D4D);
            
        } else {
            cell.textLabel.text = @"雇主说:请在包装的时候尽量保持美观";
            cell.textLabel.textColor = UIColorHexValue(0xB3B3B3);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
        
        return cell;
    } else {
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ProjectDetailModel *detailModel = _projectDetailArr[0];
    if (indexPath.section == 3) {
        if (indexPath.row == 1) {
            AddPointViewController *addPointVC = [[AddPointViewController alloc] init];
            WEAKSELF;
            addPointVC.addPointBlock = ^(SelectWorkKindModel *selectWorkKindModel, NSString *jobDetailStr, NSString *priceStr) {
                managerPrice = priceStr;
                [weakSelf.addProductionLineTableView reloadData];
            };
            addPointVC.isManager = YES;
            addPointVC.managerPrice = managerPrice;
            [self.navigationController pushViewController:addPointVC animated:YES];
        }
    }
    if (indexPath.section == 4) {
        if (indexPath.row == 0) {
            DataPicturesViewController *dataPicturesVC = [[DataPicturesViewController alloc] init];
            dataPicturesVC.imageArr = detailModel.bomImgs;
            dataPicturesVC.pictureType = BOMIMAGETYPE;
            [self.navigationController pushViewController:dataPicturesVC animated:YES];
        }
    } else if (indexPath.section == 5) {
        if (indexPath.row == 0) {
            if ([detailModel.packType isEqual:@"2"]) {
                if ([detailModel.wrapperType isEqual:@"2"]) {
                    DataPicturesViewController *dataPicturesVC = [[DataPicturesViewController alloc] init];
                    dataPicturesVC.pictureType = PACKIMAGETYPE;
                    dataPicturesVC.imageArr = detailModel.bomImgs;
                    [self.navigationController pushViewController:dataPicturesVC animated:YES];
                }
            }
        }
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)onClickStartBtn {
    whichPicker = 1;
    [self setupPickerView];
}

- (void)onClickEndBtn {
    whichPicker = 2;
    [self setupPickerView];
}

- (void)setupPickerView {
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.datePickerType = PGPickerViewType1;
    datePicker.isHiddenMiddleText = false;
    datePicker.datePickerMode = PGDatePickerModeDate;
    if (whichPicker == 1) {
        if (endComponent && ![endComponent isKindOfClass:[NSNull class]]) {
            datePicker.minimumDate = [NSDate dateWithTimeIntervalSinceNow:172800];
            datePicker.maximumDate = [NSDate setYear:endComponent.year month:endComponent.month day:endComponent.day - 1];
        }else {
            datePicker.minimumDate = [NSDate dateWithTimeIntervalSinceNow:172800];
        }
    } else {
        if (startComponent && ![startComponent isKindOfClass:[NSNull class]]) {
            datePicker.minimumDate = [NSDate setYear:startComponent.year month:startComponent.month day:startComponent.day + 1];
        }else {
            datePicker.minimumDate = [NSDate dateWithTimeIntervalSinceNow:172800];
        }
    }
    [self presentViewController:datePickManager animated:NO completion:nil];
}

#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    NSLog(@"dateComponents = %@", dateComponents);
    if (whichPicker == 1) {
        UITextField *textField = [self.view viewWithTag:103];
        textField.text = [NSString stringWithFormat:@"%ld-%ld-%ld", dateComponents.year, dateComponents.month, dateComponents.day];
        startTimeStr = textField.text;
        startComponent = dateComponents;
    } else {
        UITextField *textField = [self.view viewWithTag:104];
        textField.text = [NSString stringWithFormat:@"%ld-%ld-%ld", dateComponents.year, dateComponents.month, dateComponents.day];
        endTimeStr = textField.text;
        endComponent = dateComponents;
    }
}

- (void)saveProductionLine {
    ProjectDetailModel *detailModel = _projectDetailArr[0];
    UITextField *textField = [self.view viewWithTag:102];
    UITextField *textField2 = [self.view viewWithTag:103];
    UITextField *textField3 = [self.view viewWithTag:104];
    if (nameArr.count == 4) {
        textField4 = [self.view viewWithTag:602];
        textField5 = [self.view viewWithTag:603];
    } else if (nameArr.count == 5) {
        textField4 = [self.view viewWithTag:603];
        textField5 = [self.view viewWithTag:604];
    }
    if ([str4 hasPrefix:@"￥"]) {
        str4 = [str4 substringFromIndex:1];
    }
    if ([str5 hasPrefix:@"￥"]) {
        str5 = [str5 substringFromIndex:1];
    }
    if ([textField.text isEqualToString:@""]) {
        [LTools showMBProgressWithText:@"请输入项目总金额" addToView:self.view];
        return;
    }
    if ([startTimeStr isEqualToString:@""]) {
        [LTools showMBProgressWithText:@"请输入开始时间" addToView:self.view];
        return;
    }
    if ([endTimeStr isEqualToString:@""]) {
        [LTools showMBProgressWithText:@"请输入结束时间" addToView:self.view];
        return;
    }
    if ([str6 isEqualToString:@""]) {
        [LTools showMBProgressWithText:@"请输入物料编号" addToView:self.view];
        return;
    }
    if ([str4 isEqualToString:@""]) {
        [LTools showMBProgressWithText:@"请输入快递费用" addToView:self.view];
        return;
    }
    if ([str5 isEqualToString:@""]) {
        [LTools showMBProgressWithText:@"请输入包装费用" addToView:self.view];
        return;
    }
    NSMutableArray *machinesArr = [NSMutableArray array];
    for (int i = 0; i < _produceMachineModelArr.count; i++) {
        //        ProduceMachinesModel *produceModel = _produceMachineModelArr[i];
        AddMachineModel *model = _produceMachineModelArr[i];
        //        ProducePointTableViewCell *cell = [_addProductionLineTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i + 1 inSection:1]];
        NSDictionary *dic = @{@"machine" : @{@"id" : model.ID}, @"count" : _machineNumberArr[i]};
        [machinesArr addObject:dic];
    }
    NSMutableArray *spotsArr = [NSMutableArray array];
    for (int i = 0; i < _producePointNameArr.count; i++) {
        ProducePointModel *model = _producePointNameArr[i];
        NSDictionary *dic;
        if (i==0) {
            if (managerPrice.length>0) {
                dic = @{@"work" : @{@"id" : model.ID}, @"remark" : model.jobDetailStr, @"manager": @"1", @"forecastWage":managerPrice};
            } else {
                dic = @{@"work" : @{@"id" : model.ID}, @"remark" : model.jobDetailStr, @"manager": @"1", @"forecastWage":model.priceStr};
            }
        } else {
            dic = @{@"work" : @{@"id" : model.ID}, @"remark" : model.jobDetailStr, @"manager": @"0", @"forecastWage":model.priceStr};
        }
        [spotsArr addObject:dic];
    }
    NSMutableArray *workGroupsArr = [NSMutableArray array];
    for (int i = 0; i < _produceWorkerModelArr.count; i++) {
        WorkModel *model = _produceWorkerModelArr[i];
        //        ProducePointTableViewCell *cell = [_addProductionLineTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i + 1 inSection:2]];
        NSDictionary *dic = @{@"work" : @{@"id" : model.workId}, @"count" : _workNumberArr[i]};
        [workGroupsArr addObject:dic];
    }
    if (!machinesArr || [machinesArr isKindOfClass:[NSNull class]]) {
        [LTools showMBProgressWithText:@"请添加生产设备" addToView:self.view];
        return;
    }
    if (!_producePointNameArr || [_producePointNameArr isKindOfClass:[NSNull class]]) {
        [LTools showMBProgressWithText:@"请添加生产节点" addToView:self.view];
        return;
    }
    if (!spotsArr || [spotsArr isKindOfClass:[NSNull class]]) {
        [LTools showMBProgressWithText:@"请添加生产节点" addToView:self.view];
        return;
    }
    if (!workGroupsArr || [workGroupsArr isKindOfClass:[NSNull class]]) {
        [LTools showMBProgressWithText:@"请添加所需工人" addToView:self.view];
        return;
    }
    WEAKSELF;
    NSDictionary *dic = @{@"project" : @{@"id" : detailModel.projectId}, @"budget" : textField.text, @"expressFee" : str4, @"packingFee" : str5, @"startDate" : textField2.text, @"endDate" : textField3.text, @"machines" : machinesArr, @"workGroups" : workGroupsArr, @"spots" : spotsArr, @"contractor" : _contractorDic, @"bomNum":str6};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HYBaseHandler requestQuotationSaveParmers:dic Success:^(id obj)
     {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([obj server_Getcodecheck])
         {
             NSLog(@"%@", obj);
             [LTools showMBProgressWithText:@"保存成功" addToView:weakSelf.view];
             dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                 [self.navigationController popViewControllerAnimated:YES];
             });
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     }];
}

- (void)onClickAddNumberBtn:(UIButton *)sender {
    ProducePointTableViewCell *cell = [_addProductionLineTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag - 500 inSection:1]];
    NSInteger num = [cell.numberTextField.text integerValue];
    num ++;
    cell.numberTextField.text = [NSString stringWithFormat:@"%ld", (long)num];
    _machineNumberArr[sender.tag - 500 - 1] = cell.numberTextField.text;
}

- (void)onClickMinusNumberBtn:(UIButton *)sender {
    ProducePointTableViewCell *cell = [_addProductionLineTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag - 500 inSection:1]];
    NSInteger num = [cell.numberTextField.text integerValue];
    if (num != 1) {
        num --;
    }
    cell.numberTextField.text = [NSString stringWithFormat:@"%ld", (long)num];
    _machineNumberArr[sender.tag - 500 - 1] = cell.numberTextField.text;
}

- (void)deleteProduceMachine:(UIButton *)sender {
    if (_produceMachineNameArr.count > 0) {
        [_produceMachineNameArr removeObjectAtIndex:sender.tag - 1];
        [_machineNumberArr removeObjectAtIndex:sender.tag - 1];
        [_produceMachineModelArr removeObjectAtIndex:sender.tag - 1];
    }
    [_addProductionLineTableView reloadData];
}

- (void)onClickAddWorkerNumberBtn:(UIButton *)sender {
    ProducePointTableViewCell *cell = [_addProductionLineTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag - 500 inSection:2]];
    NSInteger num = [cell.numberTextField.text integerValue];
    num ++;
    cell.numberTextField.text = [NSString stringWithFormat:@"%ld", (long)num];
    _workNumberArr[sender.tag - 500 - 1] = cell.numberTextField.text;
}

- (void)onClickMinusWorkerNumberBtn:(UIButton *)sender {
    ProducePointTableViewCell *cell = [_addProductionLineTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag - 500 inSection:2]];
    NSInteger num = [cell.numberTextField.text integerValue];
    if (num != 1) {
        num --;
    }
    cell.numberTextField.text = [NSString stringWithFormat:@"%ld", (long)num];
    _workNumberArr[sender.tag - 500 - 1] = cell.numberTextField.text;
}

- (void)deleteProduceWorker:(UIButton *)sender {
    [_produceWorkerNameArr removeObjectAtIndex:sender.tag - 1];
    [_workNumberArr removeObjectAtIndex:sender.tag - 1];
    [_produceWorkerModelArr removeObjectAtIndex:sender.tag - 1];
    [_addProductionLineTableView reloadData];
}

- (void)deleteProducePoint:(UIButton *)sender {
    ProducePointModel *model = _producePointNameArr[sender.tag - 2];
    BOOL isSame = NO;
    NSInteger index = 0;
    for (int i = 0; i < _produceWorkerNameArr.count; i++) {
        NSString *nameStr = _produceWorkerNameArr[i];
        if ([nameStr isEqual:model.nameStr]) {
            isSame = YES;
            index = i;
            break;
        } else {
            isSame = NO;
        }
    }
    if (isSame) {
        NSInteger num = [_workNumberArr[index] integerValue];
        if (num == 1) {
            [_produceWorkerNameArr removeObjectAtIndex:sender.tag - 2];
            [_workNumberArr removeObjectAtIndex:sender.tag - 2];
            [_produceWorkerModelArr removeObjectAtIndex:sender.tag - 2];
        } else {
            _workNumberArr[index] = [NSString stringWithFormat:@"%ld", num - 1];
            WorkModel *workModel = _produceWorkerModelArr[index];
            workModel.count = _workNumberArr[index];
            _produceWorkerModelArr[index] = workModel;
        }
    } else {
        [_produceWorkerNameArr removeObjectAtIndex:sender.tag - 2];
        [_workNumberArr removeObjectAtIndex:sender.tag - 2];
        [_produceWorkerModelArr removeObjectAtIndex:sender.tag - 2];
    }
    
    [_producePointNameArr removeObjectAtIndex:sender.tag - 2];
    [_addProductionLineTableView reloadData];
}

- (void)onClickAddProduceWorkerBtn:(UIButton *)sender {
    AddWorkerViewController *addWorkerVC = [[AddWorkerViewController alloc] init];
    WEAKSELF;
    addWorkerVC.addWorkerBlock = ^(SpecialWorkerModel *model) {
        [weakSelf.produceWorkerNameArr addObject:model.name];
        [weakSelf.workNumberArr addObject:@"1"];
        WorkModel *workModel = [[WorkModel alloc] init];
        workModel.workId = model.ID;
        workModel.count = _workNumberArr.lastObject;
        [_produceWorkerModelArr addObject:workModel];
        [weakSelf.addProductionLineTableView reloadData];
    };
    [self.navigationController pushViewController:addWorkerVC animated:YES];
}

- (void)onClickAddProducePointBtn:(UIButton *)sender {
    AddPointViewController *addPointVC = [[AddPointViewController alloc] init];
    WEAKSELF;
    addPointVC.addPointBlock = ^(SelectWorkKindModel *selectWorkKindModel, NSString *jobDetailStr, NSString *priceStr) {
        _selectWorkKindModel = selectWorkKindModel;
        ProducePointModel *model = [[ProducePointModel alloc] init];
        model.nameStr = selectWorkKindModel.name;
        model.jobDetailStr = jobDetailStr;
        model.ID = selectWorkKindModel.ID;
        model.priceStr = priceStr;
        [_producePointNameArr addObject:model];
        if (_produceWorkerNameArr.count > 0) {
            BOOL isSame = NO;
            NSInteger index = 0;
            for (int i = 0; i < _produceWorkerNameArr.count; i++) {
                NSString *nameStr = _produceWorkerNameArr[i];
                if ([nameStr isEqual:selectWorkKindModel.name]) {
                    isSame = YES;
                    index = i;
                    break;
                } else {
                    isSame = NO;
                }
            }
            if (isSame) {
                NSInteger num = [_workNumberArr[index] integerValue];
                _workNumberArr[index] = [NSString stringWithFormat:@"%ld", num + 1];
                WorkModel *workModel = _produceWorkerModelArr[index];
                workModel.count = _workNumberArr[index];
                _produceWorkerModelArr[index] = workModel;
            } else {
                [_produceWorkerNameArr addObject:selectWorkKindModel.name];
                [_workNumberArr addObject:@"1"];
                WorkModel *workModel = [[WorkModel alloc] init];
                workModel.workId = model.ID;
                workModel.count = _workNumberArr.lastObject;
                [_produceWorkerModelArr addObject:workModel];
            }
        } else {
            [_produceWorkerNameArr addObject:selectWorkKindModel.name];
            [_workNumberArr addObject:@"1"];
            WorkModel *workModel = [[WorkModel alloc] init];
            workModel.workId = model.ID;
            workModel.count = _workNumberArr.lastObject;
            [_produceWorkerModelArr addObject:workModel];
        }
        [weakSelf.addProductionLineTableView reloadData];
    };
    [self.navigationController pushViewController:addPointVC animated:YES];
}

- (void)onClickAddProduceMachineBtn:(UIButton *)sender {
    AddMachineViewController *addMachineVC = [[AddMachineViewController alloc] init];
    WEAKSELF;
    addMachineVC.addMachineBlock = ^(AddMachineModel *addMachineModel) {
        _addMachineModel = addMachineModel;
        if (_produceMachineNameArr.count > 0) {
            BOOL isSame = NO;
            NSInteger index = 0;
            for (int i = 0; i < _produceMachineNameArr.count; i++) {
                NSString *nameStr = _produceMachineNameArr[i];
                if ([nameStr isEqual:addMachineModel.name]) {
                    isSame = YES;
                    index = i;
                    break;
                } else {
                    isSame = NO;
                }
            }
            if (isSame) {
                NSInteger num = [_machineNumberArr[index] integerValue];
                _machineNumberArr[index] = [NSString stringWithFormat:@"%ld", num + 1];
            } else {
                [_produceMachineNameArr addObject:addMachineModel.name];
                [_produceMachineModelArr addObject:addMachineModel];
                [_machineNumberArr addObject:@"1"];
            }
        } else {
            [_produceMachineNameArr addObject:addMachineModel.name];
            [_produceMachineModelArr addObject:addMachineModel];
            [_machineNumberArr addObject:@"1"];
        }
        [weakSelf.addProductionLineTableView reloadData];
    };
    [self.navigationController pushViewController:addMachineVC animated:YES];
}

//// 我们获取那个Cell是被点击的
//- (void)textFieldDidBeginEditing:(UITextField *)textField
//{
//    /* 获取当前cell的位置*/
//    /* 我们进行层次分析
//     * A.superview 则是 cell
//     */
//    scrollViewOffSetY = _addProductionLineTableView.contentOffset.y;
//    CGFloat Hieght = textField.superview.superview.frame.origin.y;
//    /* 获取当前点击Cell的位置*/
//    CGFloat CurrentCellY = Hieght - scrollViewOffSetY;
//    /* 获取剩余高度*/
//    CGFloat lastHeight = [UIScreen mainScreen].bounds.size.height - CurrentCellY-200;
//    remainingDistanceY = lastHeight;
//    
//    
//}
//// 我们在获取弹出键盘的高度和在做计算差值偏移
//-(void)jianpantanchu:(NSNotification*)Notification{
//    NSLog(@"%@",Notification);
//    /* 获取键盘的开始高度*/
//    NSDictionary *userInfo = [Notification userInfo];
//    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
//    CGRect keyboardRect = [aValue CGRectValue];
//    CGFloat keyBoardStart = keyboardRect.size.height;
//
//    //    CGFloat keyBoardStart = [Notification.userInfo[@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue].size.height;
//    if (remainingDistanceY < keyBoardStart) {
//        /* 获取差值*/
//        CGFloat differenceValue = keyBoardStart -remainingDistanceY;
//        beforeMigrationY = differenceValue;
//        [_addProductionLineTableView setContentOffset:CGPointMake(0, differenceValue + scrollViewOffSetY) animated:YES];
//    }
//}

// 我们为了防止tableView不能返回原始没有被点击的位置(这是防止用户在键盘弹出的时候，在滑动而造成的混乱)
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    /* 防止错乱停止编辑*/
    [self.view endEditing:YES];
}
//// 最后键盘隐藏，返回点击前的偏移
//-(void)jianpanhuishou:(NSNotification*)Notification{
//    NSLog(@"Hide");
//    [_addProductionLineTableView setContentOffset:CGPointMake(0, scrollViewOffSetY) animated:YES];
//    beforeMigrationY = 0.0;
//}

-(void)keyboardHide:(UITapGestureRecognizer*)tap {
    [self.view endEditing:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField.isEditing) {
        [textField endEditing:YES];
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    //    if (textField.tag == 100) {
    //        rightProduceNameArr[0] = textField.text;
    //    } else if (textField.tag == 102) {
    //        rightProduceNameArr[1] = textField.text;
    //    } else
    if (textField.tag >= 1001 && textField.tag < 2000) {
        _machineNumberArr[textField.tag - 1000 - 1] = textField.text;
    }
    if (textField.tag >= 2000) {
        _workNumberArr[textField.tag - 2000 - 1] = textField.text;
    }
    if (nameArr.count == 4) {
        if (textField.tag == 602) {
            str4 = textField.text;
        }
        if (textField.tag == 603) {
            str5 = textField.text;
        }
    } else if (nameArr.count == 5) {
        if (textField.tag == 601) {
            str6 = textField.text;
        }
        if (textField.tag == 603) {
            str4 = textField.text;
        }
        if (textField.tag == 604) {
            str5 = textField.text;
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
